"""
@author: Shizuku
@file: 2022-11-04-practice.py
@time: 2022/11/9 14:32
"""
import random


def exec1():
    hold = {'A': 'a', 'B': 'b', 'C': 'C', 'D': 'd', 'E': 'e'}
    gift = ['a', 'b', 'c', 'd', 'e']
    while True:
        for key in hold:
            send = random.choice(gift)
            if send != hold[key]:
                gift.remove(send)
                hold[key] = send
            else:
                continue
        if len(gift) == 0:
            print(hold)
            break
        else:
            hold = {"A": "a", "B": "b", "C": "C", "D": "d", "E": "e"}
            gift = ["a", "b", "c", "d", "e"]


def exec2():
    f1 = open('student_list.txt', 'r', encoding='utf-8')
    f2 = open('chose.txt', 'r+', encoding='utf-8')

    std_list = f1.read().splitlines()
    chose_list = f2.read().splitlines()
    rest = []

    if len(chose_list) == len(std_list)-len(rest):
        print("除请假的同学外，全都回答过问题了")
        f2.seek(0)
        f2.truncate()
    else:
        while True:
            choose = random.choice(std_list)
            if choose in rest:
                print(choose, "同学请假了")
            elif choose in chose_list:
                print(choose, "已经被抽过了")
            else:
                print("请", choose, "同学回答问题")
                f2.write(choose + '\n')
                break
    f1.close()
    f2.close()


def exec3():
    f = open('userInfo.txt', 'r+')
    user = []
    for i in f.readlines():
        user.append(i.strip().split(' '))
    user = dict(user)
    goods = {"魔方":"10", "手机":"1000", "鞋子":"200", "香蕉":"15"}
    print(user)
    wd = "欢迎进入三创购物系统"
    print(wd.center(50, "*"))
    option = input('请选择选项：\n1、登录\n2、注册\n')
    if option == "1":
        restart = True
        while restart:
            restart = False
            username = input("请输入用户名：")
            passwd = input("请输入密码：")
            if username in user and passwd == user[username].split(',')[0]:
                print("登陆成功")
                print("商品列表:\n",goods)
                pass
            else:
                restart = True
                print("用户名或密码错误，请重新输入")
    if option == "2":
        rusername = input("请输入用户名：")
        rpasswd = input("请输入密码：")
        print("注册成功，新用户获得￥100")
        f.writelines([rusername, ' ', rpasswd, ',', '100'])


exec3()
